// Messen der Ausgangsspannungen des Rigol DP831 Power Supply mit dem Picotest M3500A DMM.
// Die Messwerte werden als CSV-Datei gespeichert, und knnen mit z.B. Excel geffnet werden.

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Die Instrumente verbinden.
instrument $PT usbtmc 164E 0DAD // Picotest M3550A 6 1/2 Digit Multimeter.
instrument $DP usbtmc 1AB1 0E11 // Rigol DP831 Linear DC Power Supply.

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Konstanten und Variablen erstellen.
#FileName set "E:\Rigol DP831 Ausgang Spannung.csv" // Die Anfhrungszeichen bleiben erhalten.
#ChannelCount set 3
#Channel1MaxVolt set 8.1
#Channel2MaxVolt set 32.1
#Channel3MaxVolt set -32.1
#Step set 0.5
#WaitStep set 1000
#Separator set ;
integer Counter
integer Channel
float Level
string Measurement
float ReadDP
float ReadPT

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Die CSV-Datei vorbereiten.
Measurement set Ausgang 1
Measurement add #Separator
Measurement add Volt Set
Measurement add #Separator
Measurement add Volt DP831
Measurement add #Separator
Measurement add Volt M3500A
Measurement function save #FileName eol

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// M3500A vorbereiten.
$PT // Das Instrument auswhlen.
function scpi write *RST
function wait 1000
function scpi write :SENSe:FUNCtion "VOLTage:DC"
function scpi write :SENSe:ZERO:AUTO ON
function scpi write :SENSe:VOLTage:DC:RESolution MIN
function scpi write :SENSe:VOLTage:DC:RANGe 10
function scpi write :INPut:IMPedance:AUTO OFF
function scpi write :DATA:FEED RDG_STORE,"CALC"
function scpi write :SAMPle:COUNt 1
function scpi write :TRIGger:DELay:AUTO ON
function scpi write :TRIGger:SOURce IMMediate
$PT set wait stbmav // Beim Einlesen der Spannung warten bis die Messung fertig ist.
                    // Es wird gewartet bis das MAV-Bit im Statusbyte gesetzt wurde.

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// DP800 vorbereiten.
$DP // Das Instrument auswhlen.
function scpi write *RST
function wait 1000
// Den Lfter drosseln auf den kleinsten Wert der erlaubt ist.
// Das muss vor dem Aktivieren der Ausgnge geschehen.
function scpi write :PROJect:FAN 30

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Bei allen Ausgngen die Spannung- und Stromberwachung auf
// die gewnschten Werte setzen und die berwachung aktivieren.
Channel set 1
label ProtectionMax
function scpi write :SOUR$Channel:VOLT:PROT:LEV MAX
function scpi write :SOUR$Channel:VOLT:PROT:STAT ON
function scpi write :SOUR$Channel:CURR:PROT:LEV 0.5
function scpi write :SOUR$Channel:CURR:PROT:STAT ON
Channel add 1
Channel greater #ChannelCount
false goto ProtectionMax

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Alle Ausgnge vorbereiten.
Level set 0.5
Channel set 1
label OutputInit
function scpi write :SOUR$Channel:VOLT MIN
function scpi write :SOUR$Channel:CURR $Level
Channel add 1
Channel greater #ChannelCount
false goto OutputInit

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Warten auf den Start fr die Messung an Ausgang 1.
// - - - - - - - - - - - - - - - - - - - - - - - - - -
function beep information
function wait msg DMM mit Ausgang 1 verbinden.

// Ausgang 1 aktivieren und die Spannung schrittweise erhhen.
Counter set 1
Channel set 1
Level set 0
function scpi write :OUTP CH$Channel,ON
label Output1Step
function scpi write :SOUR$Channel:VOLT $Level
function wait #WaitStep
// Die Spannungen einlesen und speichern.
ReadDP function scpi read :MEAS:VOLT? CH$Channel
$PT
ReadPT function scpi read :INIT;:FETCH?
Measurement set Counter
Measurement add #Separator
Measurement add Level
Measurement add #Separator
Measurement add ReadDP
Measurement add #Separator
Measurement add ReadPT
Measurement function save add #FileName eol
// Nchster Spannungswert.
$DP
Counter add 1
Level add #Step
Level less #Channel1MaxVolt
true goto Output1Step
function scpi write :SOUR$Channel:VOLT MIN
function scpi write :OUTP CH$Channel,OFF

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Warten auf den Start fr die Messung an Ausgang 2.
// - - - - - - - - - - - - - - - - - - - - - - - - - -
function beep information
function wait msg DMM mit Ausgang 2 verbinden.

// Die CSV-Datei vorbereiten.
Measurement set $eol
Measurement add Ausgang 2
Measurement add #Separator
Measurement add Volt Set
Measurement add #Separator
Measurement add Volt DP831
Measurement add #Separator
Measurement add Volt M3500A
Measurement function save add #FileName eol

// TH1951 vorbereiten.
$PT
function scpi write :SENSE:VOLT:DC:RANG 100

// Ausgang 2 aktivieren und die Spannung schrittweise erhhen.
$DP
Counter set 1
Channel set 2
Level set 0
function scpi write :OUTP CH$Channel,ON
label Output2Step
function scpi write :SOUR$Channel:VOLT $Level
function wait #WaitStep
// Die Spannungen einlesen und speichern.
ReadDP function scpi read :MEAS:VOLT? CH$Channel
$PT
ReadPT function scpi read :INIT;:FETCH?
Measurement set Counter
Measurement add #Separator
Measurement add Level
Measurement add #Separator
Measurement add ReadDP
Measurement add #Separator
Measurement add ReadPT
Measurement function save add #FileName eol
// Nchster Spannungswert.
$DP
Counter add 1
Level add #Step
Level less #Channel2MaxVolt
true goto Output2Step
function scpi write :SOUR$Channel:VOLT MIN
function scpi write :OUTP CH$Channel,OFF

// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Warten auf den Start fr die Messung an Ausgang 3.
// - - - - - - - - - - - - - - - - - - - - - - - - - -
function beep information
function wait msg DMM mit Ausgang 3 verbinden.

// Die CSV-Datei vorbereiten.
Measurement set $eol
Measurement add Ausgang 3
Measurement add #Separator
Measurement add Volt Set
Measurement add #Separator
Measurement add Volt DP831
Measurement add #Separator
Measurement add Volt M3500A
Measurement function save add #FileName eol

// Ausgang 3 aktivieren und die Spannung schrittweise erhhen.
Counter set 1
Channel set 3
Level set 0
function scpi write :OUTP CH$Channel,ON
label Output3Step
function scpi write :SOUR$Channel:VOLT $Level
function wait #WaitStep
// Die Spannungen einlesen und speichern.
ReadDP function scpi read :MEAS:VOLT? CH$Channel
$PT
ReadPT function scpi read :INIT;:FETCH?
Measurement set Counter
Measurement add #Separator
Measurement add Level
Measurement add #Separator
Measurement add ReadDP
Measurement add #Separator
Measurement add ReadPT
Measurement function save add #FileName eol
// Nchster Spannungswert.
$DP
Counter add 1
Level sub #Step // Negative Spannung.
Level greater #Channel3MaxVolt // Negative Spannung.
true goto Output3Step
function scpi write :SOUR$Channel:VOLT MIN
function scpi write :OUTP CH$Channel,OFF
function scpi write :SYSTem:LOCal
$PT
$PT set wait  // Das Warten auf Daten lschen, wenn kein Parameter angegeben wird.
function scpi write :SYSTem:LOCal

// Ende.
function beep information
